package com.gxa.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.base.RespResult;
import com.gxa.domain.dto.PageDto;
import com.gxa.domain.dto.RolePageDto;
import com.gxa.domain.entity.Role;
import com.gxa.domain.entity.User;
import com.gxa.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 万事顺意
 * Created with IntelliJ IDEA.
 * User: zwj
 * Date: 2024/07/1716:30
 * Description:
 */
@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @GetMapping("/GetById")
    public RespResult getById(Integer id){
        Role byId= roleService.getById(id);
        return RespResult.success(byId);
    }
    @PostMapping("/save")
    public RespResult save(Role role){
        boolean save= roleService.save(role);
       if (save){
           return RespResult.success(save);
       }
       return RespResult.error("添加失败");
    }


    @PostMapping("/update")
    public RespResult update(Role role){
        boolean update= roleService.updateById(role);
        if (update){
            return RespResult.success(update);
        }
        return RespResult.error("修改失败");
    }
    @PostMapping("/delete")
    public RespResult delete(Integer id) {
        boolean r = roleService.removeById(id);
        if (r) {
            return RespResult.success(r);
        }
        return RespResult.error("删除失败");
    }
    @PostMapping("/searchRole")
    public RespResult searchRole(RolePageDto dto) {
        RespResult searchRole= roleService.searchRole(dto);
        return RespResult.success(searchRole);
    }

}
